<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;

class UserLog extends Model
{
    use HasFactory;
    use PimpableTrait;
    /**
     * 可批量赋值字段
     */
    public $fillable = [
        'user_id',
        'city_id',
        'mer_id',
        'visitor_num',
        'browse_num',
        'register_num',
        'order_num',
        'recharge_num',
        'list_num',
        'user_num',
        'pay_num',
        'cumulative_num',
        'deal_num',
        'amount',
        'number_num',
    ];
//    /**
//     * 默认使用倒叙的字段
//     */
//    public $defaultSortCriteria = [',desc'];

    /**
     * 进行排序的字段
     */
    public $sortable = [
        'user_num',
        'register_num',
        'visitor_num',
        'amount',
    ];

    /**
     * 可搜索字段
     */
    public $searchable = [
       'type',
        'city_id'
    ];

    /**
     * 可进行模糊查询的字段
     */
    public $searchableModels = [
        'type' => '%field%',
    ];
    /**
     * 用户类型
     */
    public $userTypeEnum = [
        'officialAccount' => '公众号',
        'applet' => '小程序',
        'h5' => 'H5',
        'pc' => 'PC',
    ];
    /**
     *可关联的用户地址
     */
    public function address(){
        return $this->belongsTo(UserAddress::class,'address_id','id');
    }


    /**
     * 可关联的用户
     */
    public function user(){
        return $this->hasMany(User::class,'user_id','id');
    }

    /**
     * 可关联的商户
     */
    public function mer(){
        return $this->belongsTo(MerchantRegister::class,'mer_id','id');
    }

    /**
     * 可关联的城市
     */
    public function city(){
        return $this->belongsTo(City::class,'city_id','id');
    }
}
